package cn.com.guage.dtm.stat.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.core.page.TableDataInfo;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.stat.domain.StatDataCoverDetail;
import cn.com.guage.dtm.stat.service.IStatDataCoverDetailService;

/**
 * 覆盖度分析详情Controller
 * 
 * @author yangdechao
 * @date 2021-07-22
 */
@Controller
@RequestMapping("/cover/coverDetail")
public class StatDataCoverDetailController extends BaseController
{
    private String prefix = "cover/coverDetail";

    @Autowired
    private IStatDataCoverDetailService statDataCoverDetailService;

    @RequiresPermissions("cover:coverDetail:view")
    @GetMapping()
    public String coverDetail()
    {
        return prefix + "/coverDetail";
    }

    /**
     * 查询覆盖度分析详情列表
     */
    @RequiresPermissions("cover:coverDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataCoverDetail statDataCoverDetail)
    {
        startPage();
        List<StatDataCoverDetail> list = statDataCoverDetailService.selectStatDataCoverDetailList(statDataCoverDetail);
        return getDataTable(list);
    }

    /**
     * 导出覆盖度分析详情列表
     */
    @RequiresPermissions("cover:coverDetail:export")
    @Log(title = "覆盖度分析详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataCoverDetail statDataCoverDetail)
    {
        List<StatDataCoverDetail> list = statDataCoverDetailService.selectStatDataCoverDetailList(statDataCoverDetail);
        ExcelUtil<StatDataCoverDetail> util = new ExcelUtil<StatDataCoverDetail>(StatDataCoverDetail.class);
        return util.exportExcel(list, "覆盖度分析详情数据");
    }

    /**
     * 新增覆盖度分析详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存覆盖度分析详情
     */
    @RequiresPermissions("cover:coverDetail:add")
    @Log(title = "覆盖度分析详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataCoverDetail statDataCoverDetail)
    {
        return toAjax(statDataCoverDetailService.insertStatDataCoverDetail(statDataCoverDetail));
    }

    /**
     * 修改覆盖度分析详情
     */
    @GetMapping("/edit/{coverDetailId}")
    public String edit(@PathVariable("coverDetailId") Long coverDetailId, ModelMap mmap)
    {
        StatDataCoverDetail statDataCoverDetail = statDataCoverDetailService.selectStatDataCoverDetailById(coverDetailId);
        mmap.put("statDataCoverDetail", statDataCoverDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存覆盖度分析详情
     */
    @RequiresPermissions("cover:coverDetail:edit")
    @Log(title = "覆盖度分析详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataCoverDetail statDataCoverDetail)
    {
        return toAjax(statDataCoverDetailService.updateStatDataCoverDetail(statDataCoverDetail));
    }

    /**
     * 删除覆盖度分析详情
     */
    @RequiresPermissions("cover:coverDetail:remove")
    @Log(title = "覆盖度分析详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataCoverDetailService.deleteStatDataCoverDetailByIds(ids));
    }
    
    @PostMapping("/showDataCoverDetailByCoverId")
  	@ResponseBody
  	public TableDataInfo showDataCoverDetailByCoverId(StatDataCoverDetail statDataCoverDetail) {
    	StatDataCoverDetail queryParams = new StatDataCoverDetail();
  		queryParams.setCoverId(statDataCoverDetail.getCoverId());
  		startPage();
  		List<StatDataCoverDetail> list =statDataCoverDetailService.selectStatDataCoverDetailList(statDataCoverDetail);
  		return getDataTable(list);
  	}
}
